<template>
  <div class="swiper-container" :class="swiperclass">
    <div class="swiper-wrapper">
      <slot></slot>
    </div>
    <div class="swiper-pagination"></div>
  </div>
</template>

<script>
import Swiper from "swiper/bundle"; //引入swiper.js
import 'swiper/swiper-bundle.min.css' //引入swiper.css
export default {
  name: "DetailSwiper",
  props: {
    perslide: {
      type: Number,
      default: 1
    },
    swiperclass: {
      type: String,
      default: 'swiper-container'
    }
  },
  mounted() {
    //获取detail组件传过来的swiperclass属性，作为class属性的值
    //console.log(this.swiperclass)
    new Swiper('.'+this.swiperclass, {
      slidesPerView: this.perslide,
      spaceBetween: 15,
      freeMode: true,
      observer: true,//修改swiper自己或子元素时，自动初始化swiper
      observeParents: true,//修改swiper的父元素时，自动初始化swiper
    })
  },
}
</script>

<style scoped lang="scss">
.swiper-wrapper{
  img {
    width: 100%;
    border-radius: 3px;
  }
}
</style>